/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package converter;

import entities.Note;
import java.math.BigDecimal;
import java.net.URI;
import java.util.Date;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlAttribute;
import javax.ws.rs.core.UriBuilder;
import javax.persistence.EntityManager;

/**
 *
 * @author Alex
 */

@XmlRootElement(name = "note")
public class NoteConverter {
    private Note entity;
    private URI uri;
    private int expandLevel;
  
    /** Creates a new instance of NoteConverter */
    public NoteConverter() {
        entity = new Note();
    }

    /**
     * Creates a new instance of NoteConverter.
     *
     * @param entity associated entity
     * @param uri associated uri
     * @param expandLevel indicates the number of levels the entity graph should be expanded@param isUriExtendable indicates whether the uri can be extended
     */
    public NoteConverter(Note entity, URI uri, int expandLevel, boolean isUriExtendable) {
        this.entity = entity;
        this.uri = (isUriExtendable) ? UriBuilder.fromUri(uri).path(entity.getId() + "/").build() : uri;
        this.expandLevel = expandLevel;
    }

    /**
     * Creates a new instance of NoteConverter.
     *
     * @param entity associated entity
     * @param uri associated uri
     * @param expandLevel indicates the number of levels the entity graph should be expanded
     */
    public NoteConverter(Note entity, URI uri, int expandLevel) {
        this(entity, uri, expandLevel, false);
    }

    /**
     * Getter for id.
     *
     * @return value for id
     */
    @XmlElement
    public Long getId() {
        return (expandLevel > 0) ? entity.getId() : null;
    }

    /**
     * Setter for id.
     *
     * @param value the value to set
     */
    public void setId(Long value) {
        entity.setId(value);
    }

    /**
     * Getter for noteText.
     *
     * @return value for noteText
     */
    @XmlElement
    public String getNoteText() {
        return (expandLevel > 0) ? entity.getNoteText() : null;
    }

    /**
     * Setter for noteText.
     *
     * @param value the value to set
     */
    public void setNoteText(String value) {
        entity.setNoteText(value);
    }

    @XmlElement
    public String getNoteDesc() {
        return (expandLevel > 0) ? entity.getNoteDesc() : null;
    }

    public void setNoteDesc(String value) {
        entity.setNoteDesc(value);
    }

    /**
     * Getter for creatorId.
     *
     * @return value for creatorId
     */
    @XmlElement
    public Long getCreatorId() {
        return (expandLevel > 0) ? entity.getCreatorId() : null;
    }

    /**
     * Setter for creatorId.
     *
     * @param value the value to set
     */
    public void setCreatorId(Long value) {
        entity.setCreatorId(value);
    }

    /**
     * Getter for columnId.
     *
     * @return value for columnId
     */
    @XmlElement
    public Long getColumnId() {
        return (expandLevel > 0) ? entity.getColumnId() : null;
    }

    /**
     * Setter for columnId.
     *
     * @param value the value to set
     */
    public void setColumnId(Long value) {
        entity.setColumnId(value);
    }

    /*
     * getNoteId
     */
    @XmlElement
    public Long getNoteId() {
        return (expandLevel > 0) ? entity.getNoteId() : null;
    }

    /*
     * Setter for Note id
     */
    public void setNoteId(Long value) {
        entity.setNoteId(value);
    }

    /**
     * Getter for noteType.
     *
     * @return value for noteType
     */
    @XmlElement
    public Long getNoteType() {
        return (expandLevel > 0) ? entity.getNoteType() : null;
    }

    /**
     * Setter for noteType.
     *
     * @param value the value to set
     */
    public void setNoteType(Long value) {
        entity.setNoteType(value);
    }

    /**
     * Getter for priority.
     *
     * @return value for priority
     */
    @XmlElement
    public Long getPriority() {
        return (expandLevel > 0) ? entity.getPriority() : null;
    }

    /**
     * Setter for priority.
     *
     * @param value the value to set
     */
    public void setPriority(Long value) {
        entity.setPriority(value);
    }

    /**
     * Getter for assignedTo.
     *
     * @return value for assignedTo
     */
    @XmlElement
    public Long getAssignedTo() {
        return (expandLevel > 0) ? entity.getAssignedTo() : null;
    }

    /**
     * Setter for assignedTo.
     *
     * @param value the value to set
     */
    public void setAssignedTo(Long value) {
        entity.setAssignedTo(value);
    }

    /**
     * Getter for estimation.
     *
     * @return value for estimation
     */
    @XmlElement()
    public BigDecimal getEstimation() {
        return (expandLevel > 0) ? entity.getEstimation() : null;
    }

    /**
     * Setter for estimation.
     *
     * @param value the value to set
     */
    public void setEstimation(BigDecimal value) {
        entity.setEstimation(value);
    }

    /**
     * Getter for startDate.
     *
     * @return value for startDate
     */
    @XmlElement
    public Date getStartDate() {
        return (expandLevel > 0) ? entity.getStartDate() : null;
    }

    /**
     * Setter for startDate.
     *
     * @param value the value to set
     */
    public void setStartDate(Date value) {
        entity.setStartDate(value);
    }

    /**
     * Getter for endDate.
     *
     * @return value for endDate
     */
    @XmlElement
    public Date getEndDate() {
        return (expandLevel > 0) ? entity.getEndDate() : null;
    }

    /**
     * Setter for endDate.
     *
     * @param value the value to set
     */
    public void setEndDate(Date value) {
        entity.setEndDate(value);
    }

    /**
     * Returns the URI associated with this converter.
     *
     * @return the uri
     */
    @XmlAttribute
    public URI getUri() {
        return uri;
    }

    /**
     * Sets the URI for this reference converter.
     *
     */
    public void setUri(URI uri) {
        this.uri = uri;
    }

    /**
     * Returns the Note entity.
     *
     * @return an entity
     */
    @XmlTransient
    public Note getEntity() {
        if (entity.getId() == null) {
            NoteConverter converter = UriResolver.getInstance().resolve(NoteConverter.class, uri);
            if (converter != null) {
                entity = converter.getEntity();
            }
        }
        return entity;
    }

    /**
     * Returns the resolved Note entity.
     *
     * @return an resolved entity
     */
    public Note resolveEntity(EntityManager em) {
        return entity;
    }
}
